package com.xbk.seckill.order.application.event.handler;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.event.EventHandler;
import com.alibaba.cola.event.EventHandlerI;
import com.alibaba.fastjson.JSON;
import com.xbk.seckill.order.domain.event.SeckillOrderEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.util.Objects;

/**
 * 订单事件处理器
 *
 * @author xiexu
 * @date 2025/2/5 17:03
 */
@Slf4j
@EventHandler
@ConditionalOnProperty(name = "message.mq.type", havingValue = "cola")
public class SeckillOrderColaEventHandler implements EventHandlerI<Response, SeckillOrderEvent> {

    @Override
    public Response execute(SeckillOrderEvent seckillOrderEvent) {
        log.info("cola|orderEvent|接收订单事件|{}", JSON.toJSON(seckillOrderEvent));
        if (Objects.isNull(seckillOrderEvent) || Objects.isNull(seckillOrderEvent.getId())) {
            log.info("cola|orderEvent|订单参数错误");
            return Response.buildSuccess();
        }
        return Response.buildSuccess();
    }

}
